package second.stackandqueue;

import java.util.LinkedList;
import java.util.List;

public class Solution03 {
}

class MyStack {

    List<Integer> queue;
    int size;

    public MyStack() {
        queue = new LinkedList<>();
        size = 0;
    }

    public void push(int x) {
        queue.add(x);
        size++;
    }

    public int pop() {
        int n = size;
        while (--n > 0) {
            queue.add(queue.remove(0));
        }
        size--;
        return queue.remove(0);
    }

    public int top() {
        int n = size;
        while (--n > 0) {
            queue.add(queue.remove(0));
        }
        Integer i = queue.remove(0);
        queue.add(i);
        return i;
    }

    public boolean empty() {
        return size == 0;
    }
}